<?php


namespace App\Http\Controllers\Forwarder;


use App\Http\Controllers\Controller;
use App\Models\ForwarderStore;
use Illuminate\Http\Request;

class ForwarderStoreController extends Controller
{
    public function selectData(Request $request){
        return $this->response(compact('serve','cargo','forwarder'));
    }

    public function index(Request $request)
    {
        $list = ForwarderStore::where('forwarder_id', $request->user()->forwarder_id)->paginate();
        return $this->response($list);
    }

    public function view($id, Request $request){
        $obj = ForwarderStore::where('forwarder_id', $request->user()->forwarder_id)->where('id',$id)->first();
        return $this->response($obj);
    }

    public function store(Request $request, ForwarderStore $obj)
    {
        $all = $request->all();
        $obj->fill($all);
        $obj->user_id = $request->user()->id;
        $obj->forwarder_id = $request->user()->forwarder_id;
        $obj->save();
        return $this->response();
    }

    public function update($id, Request $request)
    {
        $obj = ForwarderStore::where('forwarder_id', $request->user()->forwarder_id)->where('id', $id)->first();
        $obj->update($request->all());
        return $this->response();
    }

    public function destroy($id)
    {
        $obj = ForwarderStore::find($id);
        $obj->delete();
        return $this->response();
    }
}
